﻿<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>消息发布</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../static/css/font.css">
		<link rel="stylesheet" href="../../../static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

    <body>
        <div class="weadmin-nav">
            <span class="layui-breadcrumb" style="visibility: visible;">
                <a href="#">首页</a><span lay-separator="">/</span>
                <a href="#">基础数据设置</a><span lay-separator="">/</span>
                <a><cite>消息发布列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon" style="line-height:30px">ဂ</i>
            </a>
        </div>
        <div class="weadmin-body">

            <table class="layui-hide" id="msglist" lay-filter="msglist"></table>

            <script type="text/html" id="toolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="delAll"><i class="layui-icon"></i>批量删除</button>
                    <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon"></i>添加</button>
                </div>
            </script>
            <script id="barDemo" type="text/html">
                <!--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>

        </div>
        <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
        <script>
            var currentDeptLevelId = 0;//当前登录者 部门级别  0：是段
            var cuurentDeptId = 0;//当前部门id
            layui.use(['table', 'laydate', 'jquery', 'layer'], function () {
                var table = layui.table,
                    laydate = layui.laydate,
                    $ = layui.jquery,
                    layer = layui.layer;
                //执行一个laydate实例
                laydate.render({
                    elem: '#start',
                    trigger: 'click'
                });
                //执行一个laydate实例
                laydate.render({
                    elem: '#end',
                    trigger: 'click'
                });
                $.support.cors = true;
                $.ajaxSetup({
                    cache: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                })
                //获取当前 部门级别id,部门id
                $.ajax({
                    url: ApiUrl + "Dep/DeptLevel",//SelTree
                    type: 'post',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            currentDeptLevelId = data.Data.currentDeptLevelId;
                            cuurentDeptId = data.Data.cuurentDeptId;
 
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                function showList() {
                    table.render({
                        elem: '#msglist',
                        url: ApiUrl + 'MessageInfo/GetDeptMessage?deptid=' + cuurentDeptId, //数据接口,
                        cellMinWidth: 80,
                        toolbar: "#toolbar",
                        cols: [
                            [{
                                    type: 'checkbox'
                            }, {
                                    field: 'MsgID', title: '编号', sort: true, hide: true
                                }, {
                                    field: 'MsgTitle', title: '标题',width: 160,
                                }, {
                                    field: 'MsgContent', title: '内容'
                                }, {
                                    field: 'DepID', title: '部门ID', width: 120, hide: true
                                }, {
                                    field: 'DepName', title: '接收部门', width: 120
                                }, {
                                    field: 'MsgStartTime', title: '开始时间', width: 160,templet: function (d) {
                                        return d.MsgStartTime.substring(0, 10);
                                    }
                                }, {
                            field: 'MsgEndTime', title: '结束时间', width: 160, templet: function (d) {
                                return d.MsgEndTime.substring(0, 10);
                                    }
                                }, {
                                    field: 'MsgType', title: '消息类型', width: 100
                                },
                            { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 },
                            ]
                        ],
                        parseData: function (res) { //res 即为原始返回的数据
                            return {
                                "code": res.StatusCode, //解析接口状态
                                "msg": res.Info, //解析提示文本
                                "count": res.Count, //解析数据长度
                                "data": res.Data //解析数据列表
                            };
                        },
                        response: { statusCode: 200 },//规定成功的状态码，默认：0
                        event: true,
                        page: true
                    });
                }
                //头工具栏事件
                table.on('toolbar(msglist)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'delAll':
                            console.log(checkStatus.data);
                            break;
                        case 'add':
                            var add = layer.open({
                                type: 2,
                                title: "消息发布",
                                area: ['700px', '450px'],
                                fixed: false, //不固定
                                maxmin: true,
                                content: './msg_add.html',
                                end: function () {
                                    location.reload();
                                }
                            });
                            layer.full(add);
                            break;
                    };
                });
                //监听行工具事件
                table.on('tool(msglist)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'del') {
                        layer.confirm('确认删除行吗?', function (index) {
                            var postdata = { "MsgID": data.MsgID };
                            $.post(ApiUrl + 'MessageInfo/Del', postdata, function (data) {
                                if (data.StatusCode == 200) {
                                    obj.del();
                                    layer.msg(data.Info);
                                } else {
                                    layer.msg(data.Info);
                                }
                            });
                            //obj.del();
                            layer.close(index);
                        });
                    } else if (obj.event === 'edit') {
                       
                        var edit = layer.open({
                            type: 2,
                            title: "消息编辑",
                            area: ['700px', '450px'],
                            fixed: false, //不固定
                            maxmin: true,
                            content: './msg_edit.html?MsgID=' + obj.data.MsgID + "&DepID=" + obj.data.DepID +
                                "&MsgStartTime=" + obj.data.MsgStartTime.substring(0, 10) + ' ' + obj.data.MsgStartTime.substring(11) + "&MsgEndTime=" + obj.data.MsgEndTime.substring(0, 10) + ' ' + obj.data.MsgEndTime.substring(11) + 
                                "&MsgTitle=" + obj.data.MsgTitle + "&MsgContent=" + obj.data.MsgContent + "&MsgType=" + obj.data.MsgType,
                            end: function () {
                                location.reload();
                            }
                        });
                        layer.full(edit);
                    }
                });
                $(function () {



                    showList();
                    //var postdata = { "swhere": "", "startindex": "1", "endindex": "100" }
                    //$.post(ApiUrl + 'MessageInfo/Sel', postdata, function (data) {
                    //    //console.log(data);
                    //    if (data == null)
                    //        return '提交错误'
                    //    if (data.StatusCode == 200) {
                    //        showList(data.Data);
                    //    } else {
                    //        return data.Info;
                    //    }
                    //});
                })
            });
        </script>

    </body>

</html>